home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / gas_251.zip / bin_251 / bfd / libcoff.h < prev    next >
C/C++ Source or Header  |  1994-09-07  |  17KB  |  479 lines

  1. /* BFD COFF object file private structure.
  2.    Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
  3.    Written by Cygnus Support.
  4.  
  5. This file is part of BFD, the Binary File Descriptor library.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #include "bfdlink.h"
  22.  
  23. /* Object file tdata; access macros */
  24.  
  25. #define coff_data(bfd)        ((bfd)->tdata.coff_obj_data)
  26. #define exec_hdr(bfd)        (coff_data(bfd)->hdr)
  27. #define obj_symbols(bfd)    (coff_data(bfd)->symbols)
  28. #define    obj_sym_filepos(bfd)    (coff_data(bfd)->sym_filepos)
  29.  
  30. #define obj_relocbase(bfd)    (coff_data(bfd)->relocbase)
  31. #define obj_raw_syments(bfd)    (coff_data(bfd)->raw_syments)
  32. #define obj_raw_syment_count(bfd)    (coff_data(bfd)->raw_syment_count)
  33. #define obj_convert(bfd)    (coff_data(bfd)->conversion_table)
  34. #define obj_conv_table_size(bfd) (coff_data(bfd)->conv_table_size)
  35.  
  36. #define obj_coff_external_syms(bfd) (coff_data (bfd)->external_syms)
  37. #define obj_coff_strings(bfd)    (coff_data (bfd)->strings)
  38. #define obj_coff_sym_hashes(bfd) (coff_data (bfd)->sym_hashes)
  39.  
  40. /* `Tdata' information kept for COFF files.  */
  41.  
  42. typedef struct coff_tdata
  43. {
  44.   struct   coff_symbol_struct *symbols;    /* symtab for input bfd */
  45.   unsigned int *conversion_table;
  46.   int conv_table_size;
  47.   file_ptr sym_filepos;
  48.  
  49.   struct coff_ptr_struct *raw_syments;
  50.   unsigned int raw_syment_count;
  51.  
  52.   /* These are only valid once writing has begun */
  53.   long int relocbase;
  54.  
  55.   /* These members communicate important constants about the symbol table
  56.      to GDB's symbol-reading code.  These `constants' unfortunately vary
  57.      from coff implementation to implementation...  */
  58.   unsigned local_n_btmask;
  59.   unsigned local_n_btshft;
  60.   unsigned local_n_tmask;
  61.   unsigned local_n_tshift;
  62.   unsigned local_symesz;
  63.   unsigned local_auxesz;
  64.   unsigned local_linesz;
  65.  
  66.   /* Used by the COFF backend linker.  */
  67.   PTR external_syms;
  68.   char *strings;
  69.   struct coff_link_hash_entry **sym_hashes;
  70. } coff_data_type;
  71.  
  72. /* We take the address of the first element of a asymbol to ensure that the
  73.  * macro is only ever applied to an asymbol.  */
  74. #define coffsymbol(asymbol) ((coff_symbol_type *)(&((asymbol)->the_bfd)))
  75.  
  76. /* COFF linker hash table entries.  */
  77.  
  78. struct coff_link_hash_entry
  79. {
  80.   struct bfd_link_hash_entry root;
  81.  
  82.   /* Symbol index in output file.  Set to -1 initially.  Set to -2 if
  83.      there is a reloc against this symbol.  */
  84.   long indx;
  85.  
  86.   /* Symbol type.  */
  87.   unsigned short type;
  88.  
  89.   /* Symbol class.  */
  90.   unsigned char class;
  91.  
  92.   /* Number of auxiliary entries.  */
  93.   char numaux;
  94.  
  95.   /* BFD to take auxiliary entries from.  */
  96.   bfd *auxbfd;
  97.  
  98.   /* Pointer to array of auxiliary entries, if any.  */
  99.   union internal_auxent *aux;
  100. };
  101.  
  102. /* COFF linker hash table.  */
  103.  
  104. struct coff_link_hash_table
  105. {
  106.   struct bfd_link_hash_table root;
  107. };
  108.  
  109. /* Look up an entry in a COFF linker hash table.  */
  110.  
  111. #define coff_link_hash_lookup(table, string, create, copy, follow)    \
  112.   ((struct coff_link_hash_entry *)                    \
  113.    bfd_link_hash_lookup (&(table)->root, (string), (create),        \
  114.              (copy), (follow)))
  115.  
  116. /* Traverse a COFF linker hash table.  */
  117.  
  118. #define coff_link_hash_traverse(table, func, info)            \
  119.   (bfd_link_hash_traverse                        \
  120.    (&(table)->root,                            \
  121.     (boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func),    \
  122.     (info)))
  123.  
  124. /* Get the COFF linker hash table from a link_info structure.  */
  125.  
  126. #define coff_hash_table(p) ((struct coff_link_hash_table *) ((p)->hash))
  127.  
  128. /* Functions in coffgen.c.  */
  129. extern const bfd_target *coff_object_p PARAMS ((bfd *));
  130. extern struct sec *coff_section_from_bfd_index PARAMS ((bfd *, int));
  131. extern long coff_get_symtab_upper_bound PARAMS ((bfd *));
  132. extern long coff_get_symtab PARAMS ((bfd *, asymbol **));
  133. extern int coff_count_linenumbers PARAMS ((bfd *));
  134. extern struct coff_symbol_struct *coff_symbol_from PARAMS ((bfd *, asymbol *));
  135. extern boolean coff_renumber_symbols PARAMS ((bfd *));
  136. extern void coff_mangle_symbols PARAMS ((bfd *));
  137. extern boolean coff_write_symbols PARAMS ((bfd *));
  138. extern boolean coff_write_linenumbers PARAMS ((bfd *));
  139. extern alent *coff_get_lineno PARAMS ((bfd *, asymbol *));
  140. extern asymbol *coff_section_symbol PARAMS ((bfd *, char *));
  141. extern struct coff_ptr_struct *coff_get_normalized_symtab PARAMS ((bfd *));
  142. extern long coff_get_reloc_upper_bound PARAMS ((bfd *, sec_ptr));
  143. extern asymbol *coff_make_empty_symbol PARAMS ((bfd *));
  144. extern void coff_print_symbol PARAMS ((bfd *, PTR filep, asymbol *,
  145.                        bfd_print_symbol_type how));
  146. extern void coff_get_symbol_info PARAMS ((bfd *, asymbol *,
  147.                       symbol_info *ret));
  148. extern asymbol *coff_bfd_make_debug_symbol PARAMS ((bfd *, PTR,
  149.                             unsigned long));
  150. extern boolean coff_find_nearest_line PARAMS ((bfd *,
  151.                            asection *,
  152.                            asymbol **,
  153.                            bfd_vma offset,
  154.                            CONST char **filename_ptr,
  155.                            CONST char **functionname_ptr,
  156.                            unsigned int *line_ptr));
  157. extern int coff_sizeof_headers PARAMS ((bfd *, boolean reloc));
  158. extern boolean bfd_coff_reloc16_relax_section
  159.   PARAMS ((bfd *, asection *, struct bfd_link_info *, boolean *));
  160. extern bfd_byte *bfd_coff_reloc16_get_relocated_section_contents
  161.   PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *,
  162.        bfd_byte *, boolean relocateable, asymbol **));
  163. extern bfd_vma bfd_coff_reloc16_get_value PARAMS ((arelent *,
  164.                            struct bfd_link_info *,
  165.                            asection *));
  166. extern void bfd_perform_slip PARAMS ((bfd *abfd, unsigned int slip,
  167.                       asection *input_section,
  168.                       bfd_vma val));
  169.  
  170. /* Functions in cofflink.c.  */
  171.  
  172. extern struct bfd_link_hash_table *_bfd_coff_link_hash_table_create
  173.   PARAMS ((bfd *));
  174. extern boolean _bfd_coff_link_add_symbols
  175.   PARAMS ((bfd *, struct bfd_link_info *));
  176. extern boolean _bfd_coff_final_link
  177.   PARAMS ((bfd *, struct bfd_link_info *));
  178. extern boolean _bfd_coff_generic_relocate_section
  179.   PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
  180.        struct internal_reloc *, struct internal_syment *, asection **));
  181.  
  182. /* And more taken from the source .. */
  183.  
  184. typedef struct coff_ptr_struct
  185. {
  186.  
  187.         /* Remembers the offset from the first symbol in the file for
  188.           this symbol. Generated by coff_renumber_symbols. */
  189. unsigned int offset;
  190.  
  191.         /* Should the value of this symbol be renumbered.  Used for
  192.           XCOFF C_BSTAT symbols.  Set by coff_slurp_symbol_table.  */
  193. unsigned int fix_value : 1;
  194.  
  195.         /* Should the tag field of this symbol be renumbered.
  196.           Created by coff_pointerize_aux. */
  197. unsigned int fix_tag : 1;
  198.  
  199.         /* Should the endidx field of this symbol be renumbered.
  200.           Created by coff_pointerize_aux. */
  201. unsigned int fix_end : 1;
  202.  
  203.         /* Should the x_csect.x_scnlen field be renumbered.
  204.           Created by coff_slurp_symbol_table. */
  205. unsigned int fix_scnlen : 1;
  206.  
  207.         /* The container for the symbol structure as read and translated
  208.            from the file. */
  209.  
  210. union {
  211.    union internal_auxent auxent;
  212.    struct internal_syment syment;
  213.  } u;
  214. } combined_entry_type;
  215.  
  216.  
  217.  /* Each canonical asymbol really looks like this: */
  218.  
  219. typedef struct coff_symbol_struct
  220. {
  221.     /* The actual symbol which the rest of BFD works with */
  222. asymbol symbol;
  223.  
  224.     /* A pointer to the hidden information for this symbol */
  225. combined_entry_type *native;
  226.  
  227.     /* A pointer to the linenumber information for this symbol */
  228. struct lineno_cache_entry *lineno;
  229.  
  230.     /* Have the line numbers been relocated yet ? */
  231. boolean done_lineno;
  232. } coff_symbol_type;
  233. typedef struct
  234. {
  235.   void (*_bfd_coff_swap_aux_in) PARAMS ((
  236.        bfd            *abfd,
  237.        PTR             ext,
  238.        int             type,
  239.        int             class,
  240.        int             indaux,
  241.        int             numaux,
  242.        PTR             in));
  243.  
  244.   void (*_bfd_coff_swap_sym_in) PARAMS ((
  245.        bfd            *abfd ,
  246.        PTR             ext,
  247.        PTR             in));
  248.  
  249.   void (*_bfd_coff_swap_lineno_in) PARAMS ((
  250.        bfd            *abfd,
  251.        PTR            ext,
  252.        PTR             in));
  253.  
  254.  unsigned int (*_bfd_coff_swap_aux_out) PARAMS ((
  255.        bfd       *abfd,
  256.        PTR    in,
  257.        int        type,
  258.        int        class,
  259.        int     indaux,
  260.        int     numaux,
  261.        PTR        ext));
  262.  
  263.  unsigned int (*_bfd_coff_swap_sym_out) PARAMS ((
  264.       bfd      *abfd,
  265.       PTR    in,
  266.       PTR    ext));
  267.  
  268.  unsigned int (*_bfd_coff_swap_lineno_out) PARAMS ((
  269.           bfd       *abfd,
  270.           PTR    in,
  271.     PTR    ext));
  272.  
  273.  unsigned int (*_bfd_coff_swap_reloc_out) PARAMS ((
  274.           bfd     *abfd,
  275.          PTR    src,
  276.     PTR    dst));
  277.  
  278.  unsigned int (*_bfd_coff_swap_filehdr_out) PARAMS ((
  279.           bfd      *abfd,
  280.     PTR     in,
  281.     PTR     out));
  282.  
  283.  unsigned int (*_bfd_coff_swap_aouthdr_out) PARAMS ((
  284.           bfd     *abfd,
  285.     PTR     in,
  286.     PTR    out));
  287.  
  288.  unsigned int (*_bfd_coff_swap_scnhdr_out) PARAMS ((
  289.           bfd      *abfd,
  290.           PTR    in,
  291.     PTR    out));
  292.  
  293.  unsigned int _bfd_filhsz;
  294.  unsigned int _bfd_aoutsz;
  295.  unsigned int _bfd_scnhsz;
  296.  unsigned int _bfd_symesz;
  297.  unsigned int _bfd_auxesz;
  298.  unsigned int _bfd_relsz;
  299.  unsigned int _bfd_linesz;
  300.  boolean _bfd_coff_long_filenames;
  301.  void (*_bfd_coff_swap_filehdr_in) PARAMS ((
  302.        bfd     *abfd,
  303.        PTR     ext,
  304.        PTR     in));
  305.  void (*_bfd_coff_swap_aouthdr_in) PARAMS ((
  306.        bfd     *abfd,
  307.        PTR     ext,
  308.        PTR     in));
  309.  void (*_bfd_coff_swap_scnhdr_in) PARAMS ((
  310.        bfd     *abfd,
  311.        PTR     ext,
  312.        PTR     in));
  313.  void (*_bfd_coff_swap_reloc_in) PARAMS ((
  314.        bfd     *abfd,
  315.        PTR     ext,
  316.        PTR     in));
  317.  boolean (*_bfd_coff_bad_format_hook) PARAMS ((
  318.        bfd     *abfd,
  319.        PTR     internal_filehdr));
  320.  boolean (*_bfd_coff_set_arch_mach_hook) PARAMS ((
  321.        bfd     *abfd,
  322.        PTR     internal_filehdr));
  323.  PTR (*_bfd_coff_mkobject_hook) PARAMS ((
  324.        bfd     *abfd,
  325.        PTR     internal_filehdr,
  326.        PTR     internal_aouthdr));
  327.  flagword (*_bfd_styp_to_sec_flags_hook) PARAMS ((
  328.        bfd     *abfd,
  329.        PTR     internal_scnhdr,
  330.        const char *name));
  331.  asection *(*_bfd_make_section_hook) PARAMS ((
  332.        bfd     *abfd,
  333.        char    *name));
  334.  void (*_bfd_set_alignment_hook) PARAMS ((
  335.        bfd     *abfd,
  336.        asection *sec,
  337.        PTR     internal_scnhdr));
  338.  boolean (*_bfd_coff_slurp_symbol_table) PARAMS ((
  339.        bfd     *abfd));
  340.  boolean (*_bfd_coff_symname_in_debug) PARAMS ((
  341.        bfd     *abfd,
  342.        struct internal_syment *sym));
  343.  void (*_bfd_coff_reloc16_extra_cases) PARAMS ((
  344.        bfd     *abfd,
  345.        struct bfd_link_info *link_info,
  346.        struct bfd_link_order *link_order,
  347.        arelent *reloc,
  348.        bfd_byte *data,
  349.        unsigned int *src_ptr,
  350.        unsigned int *dst_ptr));
  351.  int (*_bfd_coff_reloc16_estimate) PARAMS ((
  352.        bfd *abfd,
  353.        asection *input_section,
  354.        arelent *r,
  355.        unsigned int shrink,
  356.        struct bfd_link_info *link_info));
  357.  boolean (*_bfd_coff_sym_is_global) PARAMS ((
  358.        bfd *abfd,
  359.        struct internal_syment *));
  360.  void (*_bfd_coff_compute_section_file_positions) PARAMS ((
  361.        bfd *abfd));
  362.  boolean (*_bfd_coff_relocate_section) PARAMS ((
  363.        bfd *output_bfd,
  364.        struct bfd_link_info *info,
  365.        bfd *input_bfd,
  366.        asection *input_section,
  367.        bfd_byte *contents,
  368.        struct internal_reloc *relocs,
  369.        struct internal_syment *syms,
  370.        asection **sections));
  371.  const struct reloc_howto_struct *(*_bfd_coff_rtype_to_howto) PARAMS ((
  372.        bfd *abfd,
  373.        asection *sec,
  374.        struct internal_reloc *rel,
  375.        struct coff_link_hash_entry *h,
  376.        struct internal_syment *sym,
  377.        bfd_vma *addendp));
  378.  
  379. } bfd_coff_backend_data;
  380.  
  381. #define coff_backend_info(abfd) ((bfd_coff_backend_data *) (abfd)->xvec->backend_data)
  382.  
  383. #define bfd_coff_swap_aux_in(a,e,t,c,ind,num,i) \
  384.         ((coff_backend_info (a)->_bfd_coff_swap_aux_in) (a,e,t,c,ind,num,i))
  385.  
  386. #define bfd_coff_swap_sym_in(a,e,i) \
  387.         ((coff_backend_info (a)->_bfd_coff_swap_sym_in) (a,e,i))
  388.  
  389. #define bfd_coff_swap_lineno_in(a,e,i) \
  390.         ((coff_backend_info ( a)->_bfd_coff_swap_lineno_in) (a,e,i))
  391.  
  392. #define bfd_coff_swap_reloc_out(abfd, i, o) \
  393.         ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_out) (abfd, i, o))
  394.  
  395. #define bfd_coff_swap_lineno_out(abfd, i, o) \
  396.         ((coff_backend_info (abfd)->_bfd_coff_swap_lineno_out) (abfd, i, o))
  397.  
  398. #define bfd_coff_swap_aux_out(a,i,t,c,ind,num,o) \
  399.         ((coff_backend_info (a)->_bfd_coff_swap_aux_out) (a,i,t,c,ind,num,o))
  400.  
  401. #define bfd_coff_swap_sym_out(abfd, i,o) \
  402.         ((coff_backend_info (abfd)->_bfd_coff_swap_sym_out) (abfd, i, o))
  403.  
  404. #define bfd_coff_swap_scnhdr_out(abfd, i,o) \
  405.         ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_out) (abfd, i, o))
  406.  
  407. #define bfd_coff_swap_filehdr_out(abfd, i,o) \
  408.         ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_out) (abfd, i, o))
  409.  
  410. #define bfd_coff_swap_aouthdr_out(abfd, i,o) \
  411.         ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_out) (abfd, i, o))
  412.  
  413. #define bfd_coff_filhsz(abfd) (coff_backend_info (abfd)->_bfd_filhsz)
  414. #define bfd_coff_aoutsz(abfd) (coff_backend_info (abfd)->_bfd_aoutsz)
  415. #define bfd_coff_scnhsz(abfd) (coff_backend_info (abfd)->_bfd_scnhsz)
  416. #define bfd_coff_symesz(abfd) (coff_backend_info (abfd)->_bfd_symesz)
  417. #define bfd_coff_auxesz(abfd) (coff_backend_info (abfd)->_bfd_auxesz)
  418. #define bfd_coff_relsz(abfd)  (coff_backend_info (abfd)->_bfd_relsz)
  419. #define bfd_coff_linesz(abfd) (coff_backend_info (abfd)->_bfd_linesz)
  420. #define bfd_coff_long_filenames(abfd) (coff_backend_info (abfd)->_bfd_coff_long_filenames)
  421. #define bfd_coff_swap_filehdr_in(abfd, i,o) \
  422.         ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_in) (abfd, i, o))
  423.  
  424. #define bfd_coff_swap_aouthdr_in(abfd, i,o) \
  425.         ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_in) (abfd, i, o))
  426.  
  427. #define bfd_coff_swap_scnhdr_in(abfd, i,o) \
  428.         ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_in) (abfd, i, o))
  429.  
  430. #define bfd_coff_swap_reloc_in(abfd, i, o) \
  431.         ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_in) (abfd, i, o))
  432.  
  433. #define bfd_coff_bad_format_hook(abfd, filehdr) \
  434.         ((coff_backend_info (abfd)->_bfd_coff_bad_format_hook) (abfd, filehdr))
  435.  
  436. #define bfd_coff_set_arch_mach_hook(abfd, filehdr)\
  437.         ((coff_backend_info (abfd)->_bfd_coff_set_arch_mach_hook) (abfd, filehdr))
  438. #define bfd_coff_mkobject_hook(abfd, filehdr, aouthdr)\
  439.         ((coff_backend_info (abfd)->_bfd_coff_mkobject_hook) (abfd, filehdr, aouthdr))
  440.  
  441. #define bfd_coff_styp_to_sec_flags_hook(abfd, scnhdr, name)\
  442.         ((coff_backend_info (abfd)->_bfd_styp_to_sec_flags_hook) (abfd, scnhdr, name))
  443.  
  444. #define bfd_coff_make_section_hook(abfd, name)\
  445.         ((coff_backend_info (abfd)->_bfd_make_section_hook) (abfd, name))
  446.  
  447. #define bfd_coff_set_alignment_hook(abfd, sec, scnhdr)\
  448.         ((coff_backend_info (abfd)->_bfd_set_alignment_hook) (abfd, sec, scnhdr))
  449.  
  450. #define bfd_coff_slurp_symbol_table(abfd)\
  451.         ((coff_backend_info (abfd)->_bfd_coff_slurp_symbol_table) (abfd))
  452.  
  453. #define bfd_coff_symname_in_debug(abfd, sym)\
  454.         ((coff_backend_info (abfd)->_bfd_coff_symname_in_debug) (abfd, sym))
  455.  
  456. #define bfd_coff_reloc16_extra_cases(abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr)\
  457.         ((coff_backend_info (abfd)->_bfd_coff_reloc16_extra_cases)\
  458.          (abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr))
  459.  
  460. #define bfd_coff_reloc16_estimate(abfd, section, reloc, shrink, link_info)\
  461.         ((coff_backend_info (abfd)->_bfd_coff_reloc16_estimate)\
  462.          (abfd, section, reloc, shrink, link_info))
  463.  
  464. #define bfd_coff_sym_is_global(abfd, sym)\
  465.         ((coff_backend_info (abfd)->_bfd_coff_sym_is_global)\
  466.          (abfd, sym))
  467.  
  468. #define bfd_coff_compute_section_file_positions(abfd)\
  469.         ((coff_backend_info (abfd)->_bfd_coff_compute_section_file_positions)\
  470.          (abfd))
  471.  
  472. #define bfd_coff_relocate_section(obfd,info,ibfd,o,con,rel,isyms,secs)\
  473.         ((coff_backend_info (ibfd)->_bfd_coff_relocate_section)\
  474.          (obfd, info, ibfd, o, con, rel, isyms, secs))
  475. #define bfd_coff_rtype_to_howto(abfd, sec, rel, h, sym, addendp)\
  476.         ((coff_backend_info (abfd)->_bfd_coff_rtype_to_howto)\
  477.          (abfd, sec, rel, h, sym, addendp))
  478.  
  479.